//
//  LevelSet1.m
//  TestUsingCocos2dAndCocosBuilder
//
//  Created by Ronald Ram on 1/3/13.
//  Copyright 2013 Ronald Ram. All rights reserved.
//

#import "LevelSet_01.h"

#import "MenuMgr.h"
#import "SceneMgr.h"
#import "MainMenu.h"

#import "CCBReader.h"
#import "CCControlButton.h"


typedef enum { OPEN_SUB_MENU = 10, CLOSE_SUB_MENU, SUB_MENU
} SubMenuState;


@interface LevelSet_01()
{
    BOOL canRemovePopUpSubmenu;
}

- (void) popUpSubmenu;

- (void) debugData;
- (void) startUpData;
- (void)didLoadFromCCB;

@end



@implementation LevelSet_01

/*
- (id) init
{
    if ( self = [super init] ) [self startUpData];
    return self;
}
*/


- (void) onPress: (id) sender
{
    CCControlButton *button = (CCControlButton *) sender;
    CCLayer *layer = nil;
    
    //    switch (sender.tag)
    switch (button.tag)
    {
        case POPUP_SUBMENU:
            [self popUpSubmenu];
            break;
        case CLOSE_SUB_MENU:
            [self removeChildByTag: SUB_MENU cleanup:YES];
            break;
        case LEVEL_SETS: //back btn
//            [ [SceneMgr sharedScene] switchLayer: [LevelSets node] ];
            layer = (CCLayer *) [CCBReader nodeGraphFromFile: @"LevelSets.ccbi"];
            [[SceneMgr sharedScene] switchLayer: layer];
            break;
    }
}


#pragma mark Private-Methods
- (void) startUpData
{
    self.tag = LEVEL_SETS;
}

- (void)didLoadFromCCB
{
    [self startUpData];
}

- (void) popUpSubmenu
{
    CGSize size = [CCDirector sharedDirector].winSize;
    
    CCLayer *popUp = [CCLayer node];
    popUp.tag = SUB_MENU;
    
    //add BG to submenu
    CCLayerColor *bg = [CCLayerColor layerWithColor:ccc4(0, 0, 0, 255)];
    bg.scale = 0.7;
    [popUp addChild: bg];
    
    //add menu title
    CCLabelTTF *label = [CCLabelTTF labelWithString: @"Popup Submenu\nFake Game Level" fontName: @"Copperplate" fontSize: 18];
    label.position = ccp(size.width / 2, size.height - (size.height * 0.4) );
    [popUp addChild: label];
    
    //add MenuItem btns
    CCMenuItemFont *item1 = [CCMenuItemFont itemWithString:@"Close Level 1" target:self selector:@selector(onPress:)];
    item1.tag = CLOSE_SUB_MENU;
    
    //add menuItem(s) to menu
    CCMenu *menu = [CCMenu menuWithItems:item1, nil];
    menu.position = ccp(size.width * 0.5, bg.boundingBox.size.height * 0.45);
    [popUp addChild: menu];
    
    [self addChild: popUp];
}


- (void) debugData
{
    CGSize size = [CCDirector sharedDirector].winSize;
    
    //add BG to menu
    CCLayerColor *bg = [CCLayerColor layerWithColor:ccc4(0, 128, 255, 255)];
    [self addChild: bg];
    
    //add menu title
    CCLabelTTF *label = [CCLabelTTF labelWithString: @"Level Set 1" fontName: @"Noteworthy" fontSize: 56];
    label.position = ccp(size.width / 2, size.height - (size.height * 0.15) );
    [self addChild: label];
    
    //add MenuItem btns
    CCMenuItemFont *item1 = [CCMenuItemFont itemWithString:@"Level 1" target:self selector:@selector(onPress:)];
    item1.tag = POPUP_SUBMENU;
    
    CCMenuItemFont *item2 = [CCMenuItemFont itemWithString:@"Back" target:self selector:@selector(onPress:)];
    item2.tag = MAIN_MENU;
    
    //add menuItem(s) to menu
    CCMenu *menu = [CCMenu menuWithItems:item1, item2, nil];
    [menu alignItemsVerticallyWithPadding: 30];
    [menu setColor: ccORANGE];
    
    //add menu to layer
    [self addChild: menu];
    
    canRemovePopUpSubmenu = NO;
    self.tag = LS_ONE;
}

@end
